from django_filters import *
from django_filters.rest_framework import DjangoFilterBackend, FilterSet
from rest_framework.filters import SearchFilter, OrderingFilter

from mysqldb.models import *


class MyFilterBackend(DjangoFilterBackend):
    """自己定义过滤器"""

    # def get_schema_fields(self, view):
    #     if view.action not in ["list"]:
    #         return []
    #     return super().get_schema_fields(view)


class MySearchBackend(SearchFilter):
    """自己定义搜素"""

    # def get_schema_fields(self, view):
    #     if view.action not in ["list"]:
    #         return []
    #     return super().get_schema_fields(view)


class MyOrderBackend(OrderingFilter):
    """自己定义排序"""

    # def get_schema_fields(self, view):
    #     if view.action not in ["list"]:
    #         return []
    #     return super().get_schema_fields(view)


# class AllinpayPlaceinterLogFilterSet(FilterSet):
#     """员工积分日志过滤器"""

#     pid = NumberFilter(field_name="pid", required=False, label="场所ID")
#     sid = NumberFilter(field_name="sid", required=False, label="员工ID")
#     intertype = NumberFilter(field_name="intertype", required=False, label="积分类型ID")
#     strdate = DateTimeFilter(
#         field_name="currenttime", required=False, method="filter_strdate", label="开始时间"
#     )
#     enddate = DateTimeFilter(
#         field_name="currenttime", required=False, method="filter_enddate", label="结束时间"
#     )
#     status = NumberFilter(field_name="status", required=False, label="状态")
#     post = CharFilter(field_name="post", required=False, label="兑换单")

#     def filter_strdate(self, qs, name, value):
#         lookup = "__".join([name, "gte"])
#         return qs.filter(**{lookup: value})

#     def filter_enddate(self, qs, name, value):
#         lookup = "__".join([name, "lte"])
#         return qs.filter(**{lookup: value})

#     class Meta:
#         model = AllinpayPlaceinterLog
#         fields = ["pid", "sid", "intertype", "strdate", "enddate", "status", "post"]
